package com.oceansoft.mobile.econsole.modules.api.v2.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.oceansoft.mobile.econsole.common.util.HttpClientUtil;
import com.oceansoft.mobile.econsole.modules.api.v2.service.IOrgService;
import com.oceansoft.mobile.econsole.modules.base.controller.BaseController;
import com.oceansoft.mobile.econsole.modules.base.entity.Result;
import com.oceansoft.mobile.econsole.modules.weixin.entity.DeptPolice;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.List;

import static org.springframework.web.bind.annotation.RequestMethod.GET;

/**
 * Class: ApiOrgController
 * Title: 获取辖区机构
 * Desc:
 * <p>
 * Created： wzy
 * Date： 2016/2/23.
 */
@RestController
@RequestMapping("api/Org")
public class ApiOrgController extends BaseController {


    @Resource
    IOrgService orgService;

    @RequestMapping(value = "orglist/{orgparentguid}", method = GET)
    public Result getCaseRegion(@PathVariable("orgparentguid") String orgparentguid, HttpServletRequest request) {

        String url = configInfo.getServiceInterfaceAddress();
//        url = "http://zwfw.ytga.gov.cn/api";
        String res = null;
        try {
            res = HttpClientUtil.doGet(url + "/base/dept/res-sub/" + orgparentguid);
        } catch (IOException e) {
            e.printStackTrace();
        }
        JSONObject object = JSON.parseObject(res);
        List<DeptPolice> org = JSON.parseArray(object.getString("data"), DeptPolice.class);
        if (org.isEmpty()) {
            return new Result(Result.SUCC, "暂无数据");
        }
        return new Result(Result.SUCC, org);

    }


}
